package org.eiahe.hr.performance.controller;

import lombok.RequiredArgsConstructor;
import org.ehe.common.core.BaseController;
import org.eiahe.hr.performance.domain.PerformanceCycle;
import org.eiahe.hr.performance.service.IPerformanceCycleService;
import org.ehe.common.core.domain.R;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.mybatis.core.page.PageQuery;
import org.ehe.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.dev33.satoken.annotation.SaCheckPermission;

import java.util.List;

/**
 * 绩效考核周期Controller
 *
 * @author zhangnn
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/performance/cycle")
public class PerformanceCycleController extends BaseController {

    private final IPerformanceCycleService performanceCycleService;

    /**
     * 查询绩效考核周期列表
     */
    @SaCheckPermission("performance:cycle:list")
    @GetMapping("/list")
    public TableDataInfo<PerformanceCycle> list(PerformanceCycle cycle, PageQuery pageQuery) {
        return performanceCycleService.queryPageList(cycle, pageQuery);
    }

    /**
     * 获取绩效考核周期详细信息
     */
    @SaCheckPermission("performance:cycle:query")
    @GetMapping(value = "/{cycleId}")
    public R<PerformanceCycle> getInfo(@PathVariable("cycleId") Long cycleId) {
        return R.ok(performanceCycleService.queryById(cycleId));
    }

    /**
     * 新增绩效考核周期
     */
    @SaCheckPermission("performance:cycle:add")
    @Log(title = "绩效考核周期", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody PerformanceCycle cycle) {
        return toAjax(performanceCycleService.insertByBo(cycle));
    }

    /**
     * 修改绩效考核周期
     */
    @SaCheckPermission("performance:cycle:edit")
    @Log(title = "绩效考核周期", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody PerformanceCycle cycle) {
        return toAjax(performanceCycleService.updateByBo(cycle));
    }

    /**
     * 删除绩效考核周期
     */
    @SaCheckPermission("performance:cycle:remove")
    @Log(title = "绩效考核周期", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cycleIds}")
    public R<Void> remove(@PathVariable Long[] cycleIds) {
        return toAjax(performanceCycleService.deleteWithValidByIds(List.of(cycleIds), true));
    }
}